package com.bems.pojo;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import com.bems.jdbc.common.QueryHelper;



/**
 *  用户表
 * @author 陈磊
 *
 */
public class User extends POJO 
{
		/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		//private Long id;
		private String account;
		private String password;
		private String name;//不能为空
		private String id_number;
		private String leader;
		private String authentication;
		private String numbers;
		private int status = 1;//用户状态 默认为1：可用  0:锁定
		private int islogin = 0;//是否登录 0：未登录 1：登录
		private Timestamp createtime ;//时间
		private Long group_id;//不能为空
		private String hash;
		private String contact;
		public String getAccount() {
			return account;
		}
		public void setAccount(String account) {
			this.account = account;
		}
		public String getPassword() {
			return password;
		}
		public void setPassword(String password) {
			this.password = password;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getId_number() {
			return id_number;
		}
		public void setId_number(String id_number) {
			this.id_number = id_number;
		}
		public String getLeader() {
			return leader;
		}
		public void setLeader(String leader) {
			this.leader = leader;
		}
		public String getAuthentication() {
			return authentication;
		}
		public void setAuthentication(String authentication) {
			this.authentication = authentication;
		}
		public String getNumbers() {
			return numbers;
		}
		public void setNumbers(String numbers) {
			this.numbers = numbers;
		}
		public int getStatus() {
			return status;
		}
		public void setStatus(int status) {
			this.status = status;
		}
		public int getIslogin() {
			return islogin;
		}
		public void setIslogin(int islogin) {
			this.islogin = islogin;
		}
		public Timestamp getCreatetime() {
			return createtime;
		}
		public void setCreatetime(Timestamp createtime) {
			this.createtime = createtime;
		}
		public Long getGroup_id() {
			return group_id;
		}
		public void setGroup_id(Long group_id) {
			this.group_id = group_id;
		}
		public String getHash() {
			return hash;
		}
		public void setHash(String hash) {
			this.hash = hash;
		}
		public String getContact() {
			return contact;
		}
		public void setContact(String contact) {
			this.contact = contact;
		}
		
		/**
		 *   取得组名
		 * @return
		 */
		public Group Group() 
		{
			Group group = new Group();
			return group.get(getGroup_id());		
		}
		
		/**
		 *  取得角色
		 * @return
		 */
		public java.util.List<Role> Roles() 
		{
			String sql = "SELECT r.id, r.name, r.type, r.note"+
												" FROM bems_role r"+
												" JOIN bems_grouprole gr ON gr.role_id = r.id"+
												" WHERE gr.group_id =?";
			return QueryHelper.query(Role.class, sql, getGroup_id());
		}
		
		/**
		 * 取得模板缓存
		 * @return
		 */
		public List<Template> Templates() 
		{
			String sql ="SELECT t.id, t.name, t.text, t.action, t.note,t.type"+
											" FROM bems_template t"+
											" JOIN bems_roletemplate rt ON t.id = rt.template_id"+
											" JOIN bems_role r ON rt.role_id = r.id"+
											" JOIN bems_grouprole gr ON gr.role_id = r.id"+
											" WHERE gr.group_id =?";
			return QueryHelper.query_cache("Template", getGroup_id().toString(), Template.class, sql, getGroup_id());
			
		}
		
		
}
